package com.wyg.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Arrays;

/**
 * @description:
 * @author: WYG
 * @time: 2021/4/8 16:52
 */

public class ProxyTest {
    public static void main(String[] args) {
        UserServiceImpl target = new UserServiceImpl();
        UserService userService = (UserService) Proxy.newProxyInstance(ProxyTest.class.getClassLoader(), new Class[]{UserService.class}, new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                System.out.println(Arrays.deepToString(args));
                return method.invoke(target, args);
            }
        });
        userService.addUser("wyg");
    }
}

